package main

import (
	"os"
	"sync/atomic"
)

type ProgressReader struct {
	fp   *os.File
	size int64
	read int64
}

func (r *ProgressReader) Read(p []byte) (int, error) {
	return r.fp.Read(p)
}

func (r *ProgressReader) ReadAt(p []byte, off int64) (int, error) {
	n, err := r.fp.ReadAt(p, off)
	if err != nil {
		return n, err
	}

	// Got the length have read( or means has uploaded), and you can construct your message
	atomic.AddInt64(&r.read, int64(n))

	log.Infof("progress:%d%s\n", int(float32(r.read*100/2)/float32(r.size)), `%`)

	return n, err
}

func (r *ProgressReader) Seek(offset int64, whence int) (int64, error) {
	return r.fp.Seek(offset, whence)
}
